﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class admin_product_recommended : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void recommendedProductGridView_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.Equals("cancelRecommended"))
        {

        }
    }
    protected void recommendedProductGridView_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowIndex != -1)
        {
            int id = e.Row.RowIndex + 1;
            e.Row.Cells[0].Text = id.ToString();
        }
    }

    /// <summary>
    /// 取消推荐产品
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void recommendedProductGridView_RowCommand1(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.Equals("cancelRecommended"))
        {
            string s = e.CommandArgument.ToString();
            int productId = Convert.ToInt32(s);
            DB db = new DB();
            db.cancelRecommended(productId);
            Response.Redirect("recommended.aspx");
        }
    }

    /// <summary>
    /// 推荐产品
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void allProductGridView_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.Equals("recommend"))
        {
            string s = e.CommandArgument.ToString();
            int productId = Convert.ToInt32(s);
            DB db = new DB();
            db.recommend(productId);
            Response.Redirect("recommended.aspx");
        }
    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        allProductGridView.DataSourceID = null;
        int cid = Convert.ToInt32(DropDownList1.SelectedValue);
        DB db = new DB();
        if (cid == -1)
        {
            allProductGridView.DataSource = db.getNotRecommendedProducts();
            allProductGridView.DataBind();
        }
        else
        {
            allProductGridView.DataSource = db.getProductsByCategory(cid);
            allProductGridView.DataBind();
        }
    }
}
